#include "stdafx.h"
#include "CMObject.h"

CMObject::CMObject()
{
	// default ctor must be here and not inline, so m_handle is appropriately
	// initialized to a NULL GCHandle. Otherwise it will have unpredictable
	// values since native code sees it as intptr_t
}

CMObject::CMObject(const CMObject& o) : m_handle(o.m_handle)
{
	// See remarks above
}

CMObject& CMObject::operator=(const CMObject& r)
{
	m_handle = r.m_handle;	// copies underlying GCHandle.Target
	return *this;
}

BOOL CMObject::operator==(const CMObject& r) const
{
	return (*this)->Equals(r.ThisObject());
}

CString CMObject::ToString() const
{
	return (*this)->ToString();
}

CString CMObject::TypeName() const
{
	return (*this)->GetType()->Name;
}

bool CMObject::IsNull() const
{
	return ThisObject()==nullptr;
}

void CMObject::SetNull()
{
	m_handle=nullptr;
}

bool CMObject::IsDerivedFrom(const CMObject& object) const
{
  return (*this)->GetType()->IsSubclassOf(object.ThisObject()->GetType()) || (*this)->GetType()==object.ThisObject()->GetType();
}
